import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

const baseUrl = CommonConfig.upmsUrl + '/v1' + '/department'

// 获取企业状态
export function getDepart () {
  const newUrl = baseUrl + '_flat'

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}
export function getDepartTenant () {
  const newUrl = baseUrl + '_flat:tenant'
  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 批量导入工位模板
export function getDepartAttr () {
  const newUrl = baseUrl + '_import'

  return axiosInstance.post(newUrl).then((res) => {
    return Promise.resolve((res))
  })
}

/**
 * 添加部门
 * name:设备组名称，必填
 * type:部门属性，必填
 * teamFlag:是否为班组 0：否 1：是，必填
 * remark:备注
 * sorting:排序，必填,没有传0
**/
export function addDepart (data) {
  const newUrl = baseUrl + ''

  return axiosInstance.post(newUrl, data).then((res) => {
    return Promise.resolve((res))
  })
}

/**
 * 添加子部门
 * name:设备组名称，必填
 * parentId:父id
 * type:部门属性，必填
 * teamFlag:是否为班组 0：否 1：是，必填
 * remark:备注
 * sorting:排序，必填,没有传0
**/
export function addDepartChild (data) {
  const newUrl = baseUrl + '_sub'

  return axiosInstance.post(newUrl, data).then((res) => {
    return Promise.resolve((res))
  })
}

/**
 * 编辑部门
 * id
 * name:设备组名称，必填
 * parentId:父id
 * type:部门属性，必填
 * teamFlag:是否为班组 0：否 1：是，必填
 * remark:备注
 * sorting:排序，必填,没有传0
**/
export function editDepart (data) {
  const newUrl = baseUrl + ''

  return axiosInstance.put(newUrl, data).then((res) => {
    return Promise.resolve((res))
  })
}

/**
 * 删除部门
 * id
**/
export function delDepart (id) {
  const newUrl = baseUrl + ''
  const params = {
    id
  }

  return axiosInstance.delete(newUrl, { params: params }).then((res) => {
    return Promise.resolve((res))
  })
}
